﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting.Messaging;

namespace ServiceController
{
    public delegate DataAccess.DataAccessResult CreateDeployDelegate(String SubscriptionID, String CertificatePath, String ServiceName, String DeploymentSlot, String DeployName, String PkgUrl, String ConfigFile, String Label);
    public partial class ServiceController
    {
        
        CreateDeployDelegate _CreateDeployDelegate;
        public void CreateDeployAsync(String SubscriptionID, String CertificatePath, String ServiceName, String DeploymentSlot, String DeployName, String PkgUrl, String ConfigFile, String Label, object UserState)
        {
            _CreateDeployDelegate.BeginInvoke(SubscriptionID, CertificatePath, ServiceName, DeploymentSlot,DeployName,PkgUrl, ConfigFile, Label,
                new AsyncCallback(CreateDeployCallback), UserState);
        }

        private void CreateDeployCallback(IAsyncResult ar)
        {
            AsyncResult aresult = (AsyncResult)ar;
            DataAccess.DataAccessResult result = _CreateDeployDelegate.EndInvoke(ar);
            OnCreateComplete(new ServiceControllerEventArgs()
            {
                error = result.Error,
                UserState = ar.AsyncState,
                IsOperationSuccessful = result.IsOperationSuccessful,
            });
        }

        private DataAccess.DataAccessResult CreateDeploy(String SubscriptionID, String CertificatePath, String ServiceName, String DeploymentSlot, String DeployName, String PkgUrl, String ConfigFile, String Label)
        {
            DataAccess.DataAccessResult result = da.CreateDeploy(SubscriptionID, CertificatePath, ServiceName, DeploymentSlot, DeployName, PkgUrl, ConfigFile, Label);
            return result;
        }
    }
}
